<template>
  <div class="storeUser common-container">
    <div class="common-top">
      <span class="left"></span>
      <el-button type="primary" @click="toModify('add')">添加</el-button>
    </div>
    <div class="common-bot">
      <el-table :data="tableData" stripe style="width: 100%">
        <el-table-column label="序号" type="index" width="80">
        </el-table-column>
        <el-table-column prop="name" label="名称"> </el-table-column>
        <el-table-column prop="setting.maxEmployee" label="最大员工数量"> </el-table-column>
        <el-table-column prop="setting.maxStore" label="最大门店数量"> </el-table-column>
        <el-table-column prop="setting.maxStoreChain" label="最大连锁数量"> </el-table-column>
        <el-table-column prop="setting.maxWarehouse" label="最大仓库数量"> </el-table-column>
        <el-table-column label="操作">
          <template slot-scope="scope">
            <span
              class="span-modify edit"
              @click.stop="doModify('edit', scope.row)"
              >编辑</span
            >
            <span
              class="span-modify del"
              @click.stop="doModify('del', scope.row)"
              >删除</span
            >
          </template>
        </el-table-column>
      </el-table>
    </div>
  </div>
</template>
<script>
import ManaApi from "@/api/index";
import { CodeToText } from "element-china-area-data";

export default {
  name: "storeUser",
  data() {
    return {
      tableData: [],
      roleFormat: {
        boss: "老板",
        employee: "员工",
      },
      genderFormat: {
        male: "男",
        female: "女",
      },
      nowPage: 1,
      CodeToText,
    };
  },
  methods: {
    doModify(type, item) {
      if (type == "edit") {
        this.$router.push({
          name: "membersModify",
          query: {
            type,
            id: item.id,
          },
        });
      } else if (type == "del") {
        this.$confirm("确认此操作?", "提示", {
          confirmButtonText: "确定",
          cancelButtonText: "取消",
          type: "warning",
        }).then(() => {
          ManaApi.members
            .del({
              targetIds: [item.id],
            })
            .then((res) => {
              if (res.code == 200) {
                this.$message.success("操作成功");
                this.getData();
              }
            });
        });
      }
    },
    toModify(type) {
      this.$router.push({
        name: "membersModify",
        query: {
          type,
        },
      });
    },
    getData() {
      ManaApi.members
        .list({
          limit: this.$normalMaxLimit,
          page: this.nowPage - 1,
        })
        .then((res) => {
          this.tableData = res.data;
        });
    },
    formatCity(item, type) {
      if (!item) {
        return "---";
      }
      console.log(item);
      let info = JSON.parse(JSON.stringify(item));
      let addr = info.split(",");
      console.log(addr);
      console.log(CodeToText);
      if (type == "province") {
        return CodeToText[addr[0]];
      } else {
        return CodeToText[addr[1]];
      }
    },
  },
  mounted() {
    this.getData();
  },
};
</script>
<style lang="scss" scoped>
.storeUser {
}
</style>